<template>
  <div class="orderContainer">
    <div class="option">
      <el-button
        type="primary"
        size="small"
        @click="Refresh()"
      >刷新</el-button>
    </div>
    <el-table :data="orderList" border style="width: 100%">
      <el-table-column prop="index" label="序号"></el-table-column>
      <el-table-column prop="orderNo" label="订单编号" width="250"></el-table-column>
      <el-table-column prop="name" label="运营商"></el-table-column>
      <el-table-column prop="exchangeCode" label="兑换码"></el-table-column>
      <el-table-column label="兑换图片">
        <template slot-scope="scope">
          <img
            :src="`http://www.jfqiandai.com/file${scope.row.exchangePic}`"
            style="width:80px;height:80px;overflow:hidden"
          >
        </template>
      </el-table-column>
      <el-table-column prop="integral" label="兑换积分"></el-table-column>
      <el-table-column prop="money" label="兑换金额"></el-table-column>
      <el-table-column prop="userPhone" label="用户手机号码"></el-table-column>
      <el-table-column label="订单状态" width="260">
        <template slot-scope="scope">
          <el-button type="warning" size="small" v-show="scope.row.orderStatus == 0" @click="pendding(scope.row)">待审批</el-button> 
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作" width="240">
        <template slot-scope="scope">
          <el-button @click="DeleteClick(scope.row)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      val: 1, //当前多少页
      currentPage4: 1,
      total: 0,
      orderList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
     //待审批
    pendding(row) {
      this.$confirm("更改订单状态,是否继续审批?", "提示", {
        distinguishCancelAndClose: true,
        confirmButtonText: "通过",
        cancelButtonText: "不通过",
        type: "warning"
      })
        .then(() => {
          this.status = 1;
          let url = "/order/verify";
          let params = {
            orderStatus: this.status,
            id: row.id,
            money: row.money,
            userId: row.userId
          };
          this.httpPost(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "通过"
              });
              this.getList();
            }
          });
        })
        .catch(action => {
          if (action === "cancel") {   //不通过
           this.status = 2;
          let url = "/order/verify";
          let params = {
            orderStatus: this.status,
            id: row.id
          };
          this.httpPost(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "info",
                message: "不通过"
              });
              this.getList();
            }
          });
          } else {
            this.$message({
              type: "info",
              message:"已取消"
            });
          }
        });
    },
    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
    //刷新
    Refresh() {
      this.getList();
    },

    //删除
    DeleteClick(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        distinguishCancelAndClose: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let url = "/order/edit";
          let params = {
            id: row.id,
            status: 1
          };
          this.httpPut(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功"
              });
              this.dialogVisible = false;
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //查询订单 + 搜索订单
    getList() {
      let url = "/order/findList";
      let params = {
        orderStatus: 0,
        carrierOperatorId :7,
        pageNum: this.val,
        pageSize: "10"
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.orderList = res.data.list;
          this.total = res.data.total;
          this.orderList.forEach((element, i) => {
            this.orderList[i].index = (this.val - 1) * 10 + i + 1;
          });
        } else {
          console.log("查询失败");
        }
      });
    }
  }
};
// 订单和兑换的审核
</script>

<style lang="scss" scoped>
// 订单列表
.orderContainer {
  .option {
      padding: 10px;   
  }
}
</style>

<style>
.orderContainer .el-button--success {
  margin-left: 10px !important;
}
</style>

